package com.study;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * 缓存值
 * @author ytj
 * @date 2024/5/6
 */
@SpringBootTest
@RunWith(SpringRunner.class)
public class Cache {
    @Resource
    private RedissonClient redissonClient;

    @Test
    public void cacheTest(){
        //获取对象
        RBucket<Object> bucket = redissonClient.getBucket("cache1");
        //设置值
        bucket.set("value1");
        //设置值同时设置过期时间
        bucket.set("value1",10, TimeUnit.SECONDS);
        //获取值
        Object o = bucket.get();
    }
}
